<template>
  <div>
    <el-button class="addButton" @click="addFormSpec = true"
      >添加规格</el-button
    >
    <el-dialog
      title="添加规格"
      :visible.sync="addFormSpec"
      center
      :show-close="false"
    >
      <el-form :model="form">
        <el-form-item label="规格文本:" :label-width="formLabelWidth">
          <el-input
            v-model="form.specText"
            placeholder="请输入规格文本"
          ></el-input>
        </el-form-item>
        <el-form-item label="规格值:" :label-width="formLabelWidth">
          <el-input
            v-model="form.specValue"
            placeholder="请输入规格值"
          ></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="addFormSpec = false">取消</el-button>
        <el-button type="primary" @click="confirmDialogClick">确定</el-button>
      </div>
    </el-dialog>

    <div style="margin-top: 20px">
      <el-table
        :data="tableData"
        stripe
        border
        max-height="350px"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        >
        <el-table-column type="selection" width="55"> </el-table-column>
        <el-table-column prop="id" label="编号"></el-table-column>
        <el-table-column prop="specText" label="规格展示文本"></el-table-column>
        <el-table-column prop="specValue" label="规格值"></el-table-column>
        <el-table-column fixed="right" label="操作" width="150px">
          <template v-slot="scope">
            <el-button
              class="normalButton"
              @click="($event) => editlick(scope.row)"
              type="text"
              size="small"
              >编辑</el-button
            >
            <el-button
              class="delButton"
              @click="($event) => deleClick(scope.row.id)"
              type="text"
              size="small"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
export default {
  name: "specList",
  data() {
    return {
      form: {
        id: "",
        specText: "",
        specValue: "",
      },
      formLabelWidth: "120px",
      addFormSpec: false,
      multipleSelection: [],
      tableData: [
        {
          id: "SX.000001",
          specText: "100ml",
          specValue: "1",
        },
        {
          id: "SX.000002",
          specText: "24粒/瓶",
          specValue: "2",
        },
        {
          id: "SX.000003",
          specText: "240ml",
          specValue: "3",
        },
      ],
    };
  },
  computed: {},

  methods: {
    confirmDialogClick() {
      console.log("确定");
      this.addFormSpec = false;
    },
    editlick(row) {
      console.log(row);
    },
    deleClick(id) {
      console.log(id);
    },
    // 处理选择事件
    handleSelectionChange(val) {
      console.log(val);
    },
  },
};
</script>

<style scoped>
.addButton {
  color: white;
  background-color: rgb(41, 59, 105);
}
.normalButton {
  color: rgb(51, 51, 51);
}
.delButton {
  color: rgb(190, 15, 1);
}
</style>
